package com.kyrie.utils.uniqueID;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.UUID;

/***
 * 描述: 分布式全局唯一ID生成工具类
 *
 * @author wuxiang
 * @date 2020-05-11 14:49
 */
public class UniqueIdUtils {

    private static Logger logger = LoggerFactory.getLogger(UniqueIdUtils.class);

    /**
     * 使用UUID生成分布式ID
     * @return 9f704bee8ab540e5adf7f267720987c3
     */
    public String byUUID() {
        return UUID.randomUUID().toString().replaceAll("-","");
    }

    /**
     * 基于雪花算法生成分布式ID
     * @param dataCenterId  数据中心ID
     * @param machineId     机器标识ID
     * @return
     */
    public static long bySonwFlake(long dataCenterId, long machineId){
        SnowFlake snowFlake = new SnowFlake(dataCenterId, machineId);
        return snowFlake.nextId();
    }

    public static void main(String[] args) {
        System.out.println(bySonwFlake(25,25));
    }


}
